package com.jwthhealth_pub.community.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.community.view.CommunityApplyActivity;

import java.util.ArrayList;

/**
 * 申请解读报告
 * Created by liuzhen on 2017/12/18.
 */

public class CommunityApplyAdapter extends RecyclerView.Adapter {


    private final CommunityApplyActivity mActivity;
    private final ArrayList mData;

    public CommunityApplyAdapter(CommunityApplyActivity communityApplyActivity, ArrayList data) {
        this.mActivity = communityApplyActivity;
        this.mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(mActivity, R.layout.item_community_apply, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder vh = (ViewHolder) holder;

        if (position == 0) {
            vh.applyBtn.setBackgroundResource(R.drawable.bg_rect_fill_shape_primary);
            vh.applyBtn.setText(R.string.community_apply_applay);
        } else if (position == 1) {
            vh.applyBtn.setBackgroundResource(R.drawable.bg_rect_fill_shape_orange);
            vh.applyBtn.setText(R.string.community_apply_done);
        } else {
            vh.applyBtn.setBackgroundResource(R.drawable.bg_rect_fill_shape_gray);
            vh.applyBtn.setText(R.string.community_apply_undone);
        }

        vh.applyBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (position == 0)
                    mActivity.showApplyDialog(0);
                else if (position == 1){
                    mActivity.gotoUnscramble();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        TextView name;
        TextView applyBtn;

        public ViewHolder(View itemView) {
            super(itemView);

            applyBtn = itemView.findViewById(R.id.tv_community_apple_name);
            applyBtn = itemView.findViewById(R.id.btn_community_apple);
        }
    }
}
